<!-- 出维修确认页面 -->
<template>
  <div>
    <basic-container>
      <avue-crud
        :option="option"
        :table-loading="loading"
        :search.sync="search"
        :data="data"
        :page.sync="page"
        :before-open="beforeOpen"
        v-model="form"
        ref="crud"
        :row-class-name="tableRowClassName"
        @search-change="searchChange"
        @search-reset="searchReset"
        @selection-change="selectionChange"
        @current-change="currentChange"
        @size-change="sizeChange"
        @refresh-change="refreshChange"
        @on-load="onLoad"
        @row-dblclick="rowDblclick"
      >
        <template slot-scope="{ row, index }" slot="menu">
          <el-button icon="el-icon-view" size="mini" type="text" @click="viewDetail(index, row)">详情</el-button>
        </template>
        <template slot="menuLeft">
          <div style="display: flex">
            <el-button v-if="permission.repairout_outRepair" type="primary" size="small" :disabled="ids.length > 0 ? false : true" @click="outRepair">出维修</el-button>
            <el-button v-if="permission.repairout_scrapIn" type="danger" size="small" :disabled="ids.length > 0 ? false : true" @click="repairSuccessVisible = true"
              >标记报废</el-button
            >
          </div>
        </template>
        <!--        <template slot="menuRight">-->
        <!--          <user-table-config :option="option" @confirm="(val) => handleSetUserConfig(val, pageCode)"></user-table-config>-->
        <!--        </template>-->
        <template slot="objectType" slot-scope="scope">
          <span v-if="scope.row.objectType == 'PRODUCT'">产品</span>
          <span v-if="scope.row.objectType == 'CARRIER'">载具</span>
        </template>
        <!-- 车间列表搜索 -->
        <template slot-scope="{ disabled, size }" slot="workshopNameSearch">
          <el-select :disabled="disabled" :size="size" v-model="search.workshopId" clearable placeholder="请选择" @change="changeLineList">
            <el-option v-for="item in workshopList" :key="item.workshopId" :label="item.workshopName" :value="item.workshopId"> </el-option>
          </el-select>
        </template>
        <template slot-scope="{ disabled, size }" slot="lineNameSearch">
          <el-select :disabled="disabled" :size="size" v-model="search.lineId" clearable placeholder="请选择">
            <el-option v-for="item in lineVOList" :key="item.lineId" :label="item.lineName" :value="item.lineId"> </el-option>
          </el-select>
        </template>
        <template slot="registrySourceForm">
          <span>
            <span v-if="form.registrySource == 'MANUAL'"> 手动 </span>
            <span v-else-if="form.registrySource == 'AUTO'">自动</span>
          </span>
        </template>
      </avue-crud>
    </basic-container>

    <el-dialog class="dialog" append-to-body :close-on-click-modal="false" title="详情" :visible.sync="viewDialog" width="50%" top="20vh">
      <repairDetail :rowData="rowData" :isAuto="isAuto" :activeName="activeName">
        <div class="detail-title">基本信息：</div>
        <table border="1" cellspacing="0" cellpadding="0" style="width: 100%">
          <tbody style="border: 1px solid #ebeef5">
            <tr style="height: 40px">
              <td class="tdStyle">工单号:</td>
              <td style="width: 300px">{{ rowData.workOrderNo }}</td>
              <td class="tdStyle">车间:</td>
              <td style="width: 300px">{{ rowData.workshopName }}</td>
            </tr>
            <tr style="height: 40px">
              <td class="tdStyle">产线:</td>
              <td style="width: 300px">{{ rowData.lineName }}</td>
              <td class="tdStyle">产品名称:</td>
              <td style="width: 300px">{{ rowData.partName }}</td>
            </tr>
            <tr style="height: 40px">
              <td class="tdStyle">产品编码:</td>
              <td style="width: 300px">{{ rowData.partNo }}</td>
              <td class="tdStyle">产品型号:</td>
              <td style="width: 300px">{{ rowData.partModel }}</td>
            </tr>
            <tr style="height: 40px">
              <td class="tdStyle">序列号:</td>
              <td style="width: 300px">{{ rowData.productSequenceNumber }}</td>
              <td class="tdStyle">位号:</td>
              <td>{{ rowData.locationCode }}</td>
            </tr>
            <tr style="height: 40px">
              <td class="tdStyle">条码类型:</td>
              <td style="width: 300px" v-if="rowData.objectType == 'PRODUCT'">产品</td>
              <td style="width: 300px" v-else>载具</td>
              <td class="tdStyle">产品数量:</td>
              <td>{{ rowData.quantity }}</td>
            </tr>
            <tr style="height: 40px">
              <td class="tdStyle">当前所处工序:</td>
              <td>{{ rowData.currRouteName }}</td>
              <td class="tdStyle">不良产生工序:</td>
              <td>{{ rowData.fromRouteName }}</td>
            </tr>
            <tr style="height: 40px">
              <td class="tdStyle">不良代码:</td>
              <td>{{ rowData.failureCode }}</td>
              <td class="tdStyle">不良来源:</td>
              <td>{{ rowData.registrySource | registrySource }}</td>
            </tr>
            <tr style="height: 40px">
              <td class="tdStyle">不良现象描述:</td>
              <td style="width: 300px" colspan="3">{{ rowData.failureName }}</td>
            </tr>
            <tr style="height: 40px">
              <td class="tdStyle">不良登记人员:</td>
              <td>{{ rowData.confirmByName }}</td>
              <td class="tdStyle">不良登记时间:</td>
              <td>{{ rowData.registryDate }}</td>
            </tr>
            <tr style="height: 40px">
              <td class="tdStyle">不良原因大类:</td>
              <td style="width: 300px">{{ rowData.mainCauseName }}</td>
              <td class="tdStyle">不良原因小类:</td>
              <td style="width: 300px">{{ rowData.subCauseName }}</td>
            </tr>
            <tr style="height: 40px">
              <td class="tdStyle">不良确认人员:</td>
              <td style="width: 300px">{{ rowData.confirmByName }}</td>
              <td class="tdStyle">不良确认时间:</td>
              <td style="width: 300px">{{ rowData.confirmTime }}</td>
            </tr>
            <tr style="height: 40px">
              <td class="tdStyle">进维修时间:</td>
              <td style="width: 300px">{{ rowData.repairInTime }}</td>
              <td class="tdStyle">维修执行人员:</td>
              <td style="width: 300px">{{ rowData.repairByName }}</td>
            </tr>
            <tr style="height: 40px">
              <td class="tdStyle">维修代码:</td>
              <td v-if="rowData.productHandlingResultList">{{ rowData.productHandlingResultList.map((list) => list.resultName).join('；') }}</td>
              <td class="tdStyle">维修完成时间:</td>
              <td style="width: 300px">{{ rowData.registryDate }}</td>
            </tr>
            <tr style="height: 40px">
              <td class="tdStyle">维修结果:</td>
              <td style="width: 300px" colspan="3">{{ rowData.repairName }}</td>
              <!-- <td class="tdStyle">维修图片:</td>
            <td style="width: 300px"><div style="display: flex" v-html="form.attachments"></div></td> -->
            </tr>
            <tr style="height: 40px">
              <td class="tdStyle">维修图片:</td>
              <td style="width: 300px" colspan="3">
                <div class="img-list">
                  <div style="margin: 5px 10px; display: flex; flex-direction: column" v-for="(item, index) in form.attachments" :key="index">
                    <img style="width: 100px; height: 100px" :src="item.link" @click="openPreview('0', item.link)" />
                    <button type="button" :class="`el-button el-button--text el-button--small downLoadFile${index}`" @click="handleDownload(item.link)">
                      <i class="el-icon-download"></i><span>下载</span>
                    </button>
                  </div>
                </div>
              </td>
            </tr>
            <tr style="height: 40px">
              <td class="tdStyle">维修备注:</td>
              <td style="width: 300px" colspan="3">{{ rowData.repairRemark }}</td>
            </tr>
          </tbody>
        </table>
        <div class="detail-title">维修物料信息</div>
        <table border="1" cellspacing="0" cellpadding="0" style="width: 100%">
          <tbody style="border: 1px solid #ebeef5">
            <tr style="height: 40px">
              <th class="tdStyle2">物料编码</th>
              <th class="tdStyle2">物料名称</th>
              <th class="tdStyle2">维修使用数量</th>
              <th class="tdStyle2">位号</th>
            </tr>
            <template v-if="rowData.refuelingList && rowData.refuelingList.length > 0">
              <tr style="height: 40px" v-for="item in rowData.refuelingList">
                <td class="tdStyle3">{{ item.newPartNo }}</td>
                <td class="tdStyle3">{{ item.newPartName }}</td>
                <td class="tdStyle3">{{ item.quantity }}</td>
                <td class="tdStyle3">{{ item.trackNo }}</td>
              </tr>
            </template>
            <tr v-else>
              <td colspan="4" class="detail-title noData">暂无数据</td>
            </tr>
          </tbody>
        </table>
      </repairDetail>
    </el-dialog>

    <el-dialog title="确认产品序列号是否合格" :visible.sync="dialogVisible" width="30%" :modal-append-to-body="false">
      <el-radio-group v-model="dialogForm.isQualified" @input="inputIsQualified">
        <el-radio label="0">合格</el-radio>
        <el-radio label="1">不合格</el-radio>
      </el-radio-group>
      <div style="margin-top: 20px" v-if="dialogForm.isQualified == 0"></div>
      <span v-if="dialogForm.isQualified == 0">工序：</span>
      <el-select v-model="dialogForm.qualifiedRouteId" placeholder="请选择" v-if="dialogForm.isQualified == 0">
        <el-option v-for="item in fromRouteOptions" :key="item.fromRouteId" :label="item.fromRouteName" :value="item.fromRouteId"> </el-option>
      </el-select>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" icon="el-icon-check" v-preventReClick @click="repairOutData">保 存</el-button>
        <el-button size="small" icon="el-icon-delete" @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
    <el-dialog title="填写报废原因" :visible.sync="repairSuccessVisible" :modal-append-to-body="false" :show-close="true" :close-on-press-escape="false" width="40%">
      <el-form ref="repairSuccessForm" :model="repairSuccessForm" :rules="rulesSuccessForm" label-width="80px">
        <el-form-item label="报废原因" prop="scrapReason">
          <el-input type="textarea" :rows="2" placeholder="请输入报废原因" v-model="repairSuccessForm.scrapReason"></el-input>
        </el-form-item>
        <el-form-item label="报废图片">
          <el-upload
            ref="fileUpload"
            class="upload-demo"
            drag
            multiple
            :limit="5"
            action="/api/blade-resource/oss/endpoint/put-file-attach"
            accept=".png,.jpg"
            list-type="picture"
            :headers="headersObj"
            :on-remove="removeFile"
            :on-success="pictureUploadSuccess"
            :before-upload="beforeUpload"
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            <div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
          </el-upload>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" icon="el-icon-circle-plus-outline" @click="scrapIn">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import repairDetail from '@/components/repair/detail.vue';
import { getList, getDetail, getWorkshopAndLine, repairOut } from '@/api/repair/repairout.js';
import { getRoutesByWo } from '@/api/product/part-lock';
import { flagScrap } from '@/api/repair/failureconfirm';
import { compressImg } from '@/util/compressImg';
import website from '@/config/website';
import { getToken } from '@/util/auth';
import { mapGetters } from 'vuex';
import userTableConfig from '@/components/user-table-config';
import userConfig from '@/mixins/userConfig';

export default {
  name: 'RepairRepairOut',
  components: {
    repairDetail,
    userTableConfig
  },
  mixins: [userConfig()],
  filters: {
    registrySource(value) {
      switch (value) {
        case 'AUTO':
          return '自动';
        case 'MANUAL':
          return '手动';
        default:
          break;
      }
    }
  },
  data() {
    return {
      pageCode: 'REPAIR_OUT',
      fileList: [],
      returnObject: {},
      isAuto: false,
      activeName: 'first',
      rowData: {},
      viewDialog: false,
      fromRouteOptions: [], // 不良工序列表
      form: {
        workshopId: '',
        lineId: '',
        objectType: 'PRODUCT',
        attachments: []
      },
      search: {},
      query: {},
      groupCodes: [],
      loading: true,
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      selectionList: [],
      option: {
        height: 'calc(100vh - 472px)',
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 3,
        border: true,
        index: true,
        indexLabel: '序号',
        dialogClickModal: false,
        labelWidth: 120,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        menuWidth: 100,
        viewBtn: false,
        columnBtn: false,
        column: [
          {
            label: '序列号',
            prop: 'productSequenceNumber',
            order: 1,
            search: true,
            searchSpan: 5,
            searchOrder: 2,
            searchLabelWidth: 100,
            minWidth: 100
          },
          {
            label: '包装条码',
            prop: 'packingSn',
            hide: true,
            search: true,
            searchSpan: 5,
            searchOrder: 2,
            searchLabelWidth: 100,
            minWidth: 100
          },
          {
            label: '载具编码',
            prop: 'vehicleSn',
            hide: true,
            search: true,
            searchSpan: 5,
            searchOrder: 2,
            searchLabelWidth: 100,
            minWidth: 100
          },
          {
            label: '工单号',
            prop: 'workOrderNo',
            search: true,
            searchSpan: 5,
            order: 8,
            searchLabelWidth: 80,
            searchOrder: 4
          },
          {
            label: '条码类型',
            prop: 'objectType',
            searchLabelWidth: 100,
            viewDisplay: false,
            searchSpan: 4,
            search: true,
            searchOrder: 1,
            type: 'select',
            value: 'PRODUCT',
            searchValue: 'PRODUCT',
            control: (val, form) => {
              if (form.objectType == 'PRODUCT') {
                return {
                  productSequenceNumber: {
                    display: true
                  },
                  packingSn: {
                    display: false
                  },
                  vehicleSn: {
                    display: false
                  }
                };
              } else if (form.objectType == 'PACKING') {
                return {
                  productSequenceNumber: {
                    display: false
                  },
                  packingSn: {
                    display: true
                  },
                  vehicleSn: {
                    display: false
                  }
                };
              } else if (form.objectType == 'CARRIER') {
                return {
                  productSequenceNumber: {
                    display: false
                  },
                  packingSn: {
                    display: false
                  },
                  vehicleSn: {
                    display: true
                  }
                };
              }
            },
            change: ({ value }) => {
              if (value == 'PRODUCT') {
                this.search.packingSn = '';
                this.search.vehicleSn = '';
              } else if (value == 'PACKING') {
                this.search.productSequenceNumber = '';
                this.search.vehicleSn = '';
              } else if (value == 'CARRIER') {
                this.search.packingSn = '';
                this.search.productSequenceNumber = '';
              }
            },
            dicData: [
              {
                label: '序列号',
                value: 'PRODUCT'
              },
              {
                label: '包装条码',
                value: 'PACKING'
              },
              {
                label: '载具',
                value: 'CARRIER'
              }
            ]
            // searchRules: [
            //   {
            //     required: true,
            //     message: '请选择条码类型',
            //     trigger: 'change'
            //   }
            // ]
          },
          {
            label: '产品数量',
            prop: 'quantity',
            viewDisplay: false
          },
          {
            label: '当前所处工序',
            prop: 'currRouteName',
            viewDisplay: false
          },
          {
            label: '不良产生工序',
            prop: 'fromRouteName',
            order: 3
          },
          {
            label: '不良来源',
            prop: 'registrySource',
            order: 2,
            hide: true,
            type: 'select',
            dicData: [
              {
                label: '自动',
                value: 'AUTO'
              },
              {
                label: '手动',
                value: 'MANUAL'
              }
            ]
          },
          {
            label: '不良代码',
            prop: 'failureCode',
            order: 4
          },
          {
            label: '不良登记人员',
            minWidth: 120,
            prop: 'registryByName',
            hide: true,
            order: 5
          },
          {
            label: '不良登记时间',
            prop: 'registryDate',
            hide: true,
            type: 'datetime',
            order: 6
          },
          {
            label: '不良现象描述',
            minWidth: 120,
            prop: 'failureName',
            span: 24,
            order: 7,
            type: 'textarea',
            minRows: 3,
            maxRows: 3,
            row: true
          },
          {
            label: '产品编码',
            prop: 'partNo',
            searchSpan: 5,
            searchLabelWidth: 80,
            search: true,
            order: 12,
            searchOrder: 5
          },
          {
            label: '产品名称',
            prop: 'partName',
            order: 11
          },
          {
            label: '产品型号',
            prop: 'partModel',
            order: 13
          },
          {
            label: '不良原因大类',
            minWidth: 120,
            prop: 'mainCauseName',
            order: 14,
            hide: true
          },
          {
            label: '不良原因小类',
            minWidth: 120,
            prop: 'subCauseName',
            order: 15,
            hide: true
          },
          {
            label: '不良确认人员',
            minWidth: 120,
            prop: 'confirmByName',
            order: 16,
            hide: true
          },
          {
            label: '不良确认时间',
            minWidth: 120,
            prop: 'confirmTime',
            type: 'datetime',
            order: 17,
            hide: true
          },
          {
            label: '进维修时间',
            minWidth: 120,
            prop: 'repairInTime',
            type: 'datetime',
            order: 18,
            hide: true
          },
          {
            label: '维修执行人员',
            prop: 'repairByName',
            order: 19,
            hide: true
          },
          {
            label: '维修代码',
            prop: 'repairCode',
            order: 20,
            hide: true
          },
          {
            label: '维修完成时间',
            minWidth: 120,
            prop: 'registryDate',
            order: 21,
            type: 'datetime',
            hide: true
          },
          {
            label: '维修结果',
            prop: 'repairName',
            order: 22,
            span: 24,
            type: 'textarea',
            minRows: 3,
            maxRows: 3,
            hide: true
          }
        ]
      },
      data: [],
      dialogVisible: false,
      dialogForm: {
        isQualified: null
      },
      // 车间列表
      workshopList: [],
      repairSuccessVisible: false,
      repairSuccessForm: {
        scrapReason: ''
      },
      rulesSuccessForm: {
        scrapReason: [{ required: true, message: '请输入报废原因', trigger: 'blur' }]
      },
      lineVOList: []
    };
  },
  computed: {
    ...mapGetters(['permission']),
    headersObj() {
      let header = { Authorization: `Basic ${Base64.encode(`${website.clientId}:${website.clientSecret}`)}` };
      header['Blade-Auth'] = 'bearer ' + getToken();
      return header;
    },
    permissionList() {
      return {
        viewBtn: this.vaildData(this.permission.repairout_view, false)
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids;
    }
  },
  watch: {},
  mounted() {
    this.$nextTick(() => {
      this.$structuralSplit();
    });
    this.getWorkShopList();
  },
  methods: {
    removeFile(file) {
      this._forEach(this.fileList, (item, index) => {
        if (item.link === file.response.data.link) {
          this.fileList.splice(index, 1);
        }
      });
      this.returnObject['attachmentUrls'] = JSON.stringify(this.fileList);
    },
    pictureUploadSuccess(res) {
      this.fileList.push({
        attachmentId: res.data.attachId,
        link: res.data.link
      });
      this.returnObject['attachmentUrls'] = JSON.stringify(this.fileList);
    },
    beforeUpload(file) {
      return new Promise(async (resolve, reject) => {
        if (!file.type.includes('image')) {
          this.$message.warning('请上传图片');
          reject(new Error('请上传图片'));
          return;
        }
        if (file.type != 'image/png' && file.type != 'image/jpeg') {
          this.$message.warning('请上传正确的文件类型！');
          reject(new Error('请上传正确的文件类型！'));
          return;
        }
        try {
          const newFile = await compressImg(file);
          resolve(newFile);
        } catch (e) {
          console.log(e);
        }
      });
    },
    // 获取车间列表及产线接口
    getWorkShopList() {
      getWorkshopAndLine().then((res) => {
        this.workshopList = res.data.data;
      });
    },
    // 修改产线列表数据
    changeLineList(val) {
      // this.form.lineId = ''
      this.$set(this.search, 'lineId', '');

      for (let item of this.workshopList) {
        if (item.workshopId === val) {
          // this.option.column[9].dicData = item.lineVOList
          this.lineVOList = item.lineVOList;
          break;
        } else {
          // this.option.column[9].dicData = []
          this.lineVOList = [];
        }
      }
    },
    // 出维修操作
    repairOutData() {
      if (!this.dialogForm.isQualified) {
        this.$message({
          type: 'warning',
          message: '请选择合格或不合格！'
        });
        return;
      }
      if (this.dialogForm.isQualified == 0 && !this.dialogForm.qualifiedRouteId) {
        this.$message({
          type: 'warning',
          message: '请选择工序！'
        });
        return;
      }
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      repairOut(parseInt(this.dialogForm.isQualified), this.dialogForm.qualifiedRouteId, String(this.groupCodes), ids).then((res) => {
        if (res.data.code === 200) {
          this.$message({
            type: 'success',
            message: res.data.msg
          });
          this.groupCodes = [];
          this.dialogVisible = false;
          this.dialogForm.qualifiedRouteId = '';
          this.dialogForm.isQualified = null;
          this.fromRouteOptions = [];
          this.refreshChange();
        }
      });
    },
    beforeOpen(done, type) {
      if (['edit', 'view'].includes(type)) {
        getDetail(this.form.id).then((res) => {
          this.form = res.data.data;
        });
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.search.objectType = 'PRODUCT';
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      if (params.receiveDate && params.receiveDate.length > 0) {
        params.startTime = params.receiveDate[0];

        params.endTime = this.$moment(this.$moment(params.receiveDate[1]).add(1, 'days')).format('YYYY-MM-DD');
        delete params.receiveDate;
      }
      if (params.objectType == 'PRODUCT') {
        params.objectType = 'PRODUCT';
        params.productSequenceNumber = params.productSequenceNumber;
      }
      if (params.objectType == 'PACKING') {
        params.objectType = 'PRODUCT';
        params.productSequenceNumber = params.packingSn;
      }
      if (params.objectType == 'CARRIER') {
        params.objectType = 'CARRIER';
        params.productSequenceNumber = params.vehicleSn;
      }

      delete params.packingSn;
      delete params.vehicleSn;
      params.statusStr = '8';
      this.query = params;
      getList(Object.assign(params, this.query)).then((res) => {
        this.badCodeEntry(this.query.productSequenceNumber, 'input', this.query.workOrderNo, this.query.partNo);
        this.query.productSequenceNumber = '';
        this.query.workOrderNo = '';
        this.query.partNo = '';
        this.search.workOrderNo = '';
        this.search.productSequenceNumber = '';
        this.search.partNo = '';
      });
      done();
    },
    rowDblclick(row) {
      if (this.selectionList.length > 0) {
        let findIndex = this.selectionList.findIndex((item) => item.id === row.id);
        if (findIndex > -1) {
          this.selectionList.splice(findIndex, 1);
          row.isCheck = '';
        }
        //删除同组编码
        let findIndex2 = this.groupCodes.findIndex((productSequenceNumber) => productSequenceNumber === row.productSequenceNumber);
        if (findIndex2 > -1) {
          this.groupCodes.splice(findIndex2, 1);
        }
      }
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page);
    },
    tableRowClassName({ row, rowIndex }) {
      let className = row.isCheck ? 'repair-select-row' : '';
      return className;
    },
    badCodeEntry(productSequenceNumber, type, workOrderNo, partNo) {
      let data = this._cloneDeep(this.data);
      let removes = this._remove(data, (item) => {
        if (productSequenceNumber) {
          if (item.productSequenceNumber === productSequenceNumber && this.selectionList.length > 0 && item.workOrderNo != this.selectionList[0].workOrderNo) {
            if (this.search.objectType === 'PRODUCT') {
              this.$message.warning('请输入属于同一工单的序列号！');
            } else if (this.search.objectType === 'PACKING') {
              this.$message.warning('请输入属于同一工单的包装条码！');
            } else {
              this.$message.warning('请输入属于同一工单的载具编码！');
            }
            return;
          }
          return item.productSequenceNumber === productSequenceNumber && item.objectType == this.query.objectType;
        }
        if (workOrderNo) {
          return item.workOrderNo == workOrderNo && item.objectType == this.query.objectType;
        }
        if (partNo) {
          return item.partNo == partNo && item.objectType == this.query.objectType;
        }
      });

      if (removes.length > 0) {
        removes.forEach((item) => {
          if (item.productSequenceNumber === productSequenceNumber && item.groupcode) {
            //&& item.groupCode
            this.$confirm(`当前条码${productSequenceNumber}有相同组编码，相同组条码是否解除不良?`, {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.groupCodes.push(item.groupcode);
              this.groupCodes = this._uniq(this.groupCodes);
              // console.log(this.groupCodes, 998888);
            });
          }
        });
      }
      let items = removes.map((item) => {
        item.isCheck = type === 'input' ? true : false;
        return item;
      });

      if (workOrderNo && this.selectionList.length > 0 && workOrderNo != this.selectionList[0].workOrderNo) {
        this.$message.warning('请输入同一工单号！');
        return;
      }
      this.data = type === 'input' ? items.concat(data) : data.concat(items);
      this.filtersFailureSequenceNumber();
    },
    filtersFailureSequenceNumber() {
      this.selectionList = this._filter(this.data, (item) => {
        return item.isCheck === true;
      });
    },
    onLoad(page, params = {}) {
      this.loading = true;
      // 	数据状态，不良确认：1，待维修：2，进维修：6，维修中：7，维修结束：8，出维修：9
      params.statusStr = '8';
      getList(Object.assign(params)).then((res) => {
        const data = res.data.data;
        // this.page.total = data.total;
        this.data = data;
        this.loading = false;
        this.selectionClear();
      });
    },
    // 维修报废
    scrapIn() {
      this.$refs.repairSuccessForm.validate((valid, done) => {
        flagScrap(this.ids.join(','), this.fileList, this.repairSuccessForm.scrapReason, 1).then((res) => {
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.groupCodes = [];
          // done();
          this.$refs.repairSuccessForm.resetFields();
          this.onLoad(this.page);
          this.repairSuccessVisible = false;
        });
      });
    },
    outRepair() {
      this.dialogVisible = true;
    },
    inputIsQualified(value) {
      if (value == 0) {
        this.findWorkOrderNo(this.selectionList[0].workOrderId);
      } else {
        this.dialogForm.qualifiedRouteId = '';
      }
    },
    // 根据工单id获取工序
    findWorkOrderNo(workorderId) {
      getRoutesByWo(workorderId).then((res) => {
        this.fromRouteOptions = res.data.data.map((d) => {
          return {
            fromRouteCode: d.code,
            fromRouteId: d.id,
            fromRouteName: d.name
          };
        });
      });
    },
    openPreview(index = 0, link) {
      this.$ImagePreview([{ url: link }], index, {
        closeOnClickModal: false
      });
    },
    handleDownload(link) {
      window.open(`${link}`);
    },
    viewDetail(idx, row) {
      // 维修物料信息
      this.form.attachments = row.imageList || [];
      this.viewDialog = true;
      this.isAuto = row.registrySource == 'AUTO';
      this.rowData = structuredClone(row); // 基本信息
      this.activeName = 'first';
    }
  }
};
</script>

<style scoped lang="scss">
.img-list {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}
::v-deep .el-table {
  margin-bottom: 10px;
}
.tdStyle {
  background: #fafafa;
  font-weight: 700;
  color: #909399;
  text-align: right;
  width: auto;
  padding-right: 20px;
  white-space: nowrap;
}
.tdStyle2 {
  white-space: nowrap;
  background: #fafafa;
  font-weight: 700;
  padding: 0 10px;
}
.tdStyle3 {
  text-align: center;
}
td {
  padding: 5px;
  border: 1px solid #ebeef5;
}

::v-deep .el-table .repair-select-row {
  background-color: #caf982 !important;
}
.detail-title {
  font-weight: bold;
  font-size: 14px;
  margin: 10px 0;
}
.detail-title.noData {
  text-align: center;
}
</style>
